package com.jvyou.app.ds.controller;



import com.jvyou.app.ds.domain.entity.QuestionOption;
import com.jvyou.app.ds.service.QuestionOptionService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jvyou.app.common.domain.model.Result;
import com.jvyou.app.common.enums.HttpCodeEnum;

import java.util.List;

/**
 * 题目选项表(QuestionOption)表控制层
 *
 * @author 橘柚
 * @since 2025-04-20 22:44:21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/questionOption")
public class QuestionOptionController  {
    
    private final QuestionOptionService questionOptionService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("ds:questionOption:get")
    public Result<QuestionOption> selectOne(@PathVariable Long id) {
        return Result.success(questionOptionService.getById(id));
    }

    /**
     * 根据题目获取选项
     *
     * @param questionId 题目ID
     * @return 题目选项
     */
    @GetMapping("/getByQuestion/{questionId}")
    @SaCheckPermission("ds:questionOption:get")
    public Result<List<QuestionOption>> getByQuestion(@PathVariable Long questionId) {
        return Result.success(questionOptionService.getByQuestion(questionId));
    }

    /**
     * 新增数据
     *
     * @param questionOption 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaCheckPermission("ds:questionOption:insert")
    public Result<QuestionOption> insert(@RequestBody QuestionOption questionOption) {
        boolean success = questionOptionService.save(questionOption);
        return success ? Result.success(questionOption) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改数据
     *
     * @param questionOption 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("ds:questionOption:update")
    public Result<Boolean> updateById(@RequestBody QuestionOption questionOption) {
        boolean success = questionOptionService.updateById(questionOption);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("ds:questionOption:delete")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = questionOptionService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

